package com.farm.observer;

import com.farm.strategy.PathPlanner;
import com.farm.strategy.WetSoilStrategy;

// 具体观察者类 - 农机设备
public class AgriculturalMachineObserver implements Observer {
    private String machineName;

    public AgriculturalMachineObserver(String machineName) {
        this.machineName = machineName;
    }

    @Override
    public void update(float temperature, float humidity, float soilMoisture) {
        System.out.println(machineName + " 收到环境更新: ");
        System.out.println(machineName + ":" +   "温度: " + temperature + "°C, 湿度: " + humidity + "%, 土壤湿度: " + soilMoisture + "%");

        // 根据环境数据调整行为
        if (soilMoisture > 70) {
            System.out.println("  警告: 土壤湿度过高，可能需要调整作业计划");
            PathPlanner planner = new PathPlanner();
            planner.setStrategy(new WetSoilStrategy());
            planner.executePathPlanning(machineName);
        }
    }
}
